#include <func.h>


//不会打印printf("free success\n");
//这样不能释放p1
void* thread_func(void *p)
{
    void *p1=malloc(20);
    printf("I am child thread, start free\n");

    sleep(1);
    free(p1);
    printf("free success\n");
    return NULL;
}

int main()
{
    pthread_t th_id;
    int ret=pthread_create(&th_id,NULL,thread_func,NULL);
    THREAD_ERR_CHECK(ret,"pthread_creat");
    printf("I am main thread\n");

    ret=pthread_cancel(th_id);
    THREAD_ERR_CHECK(ret,"pthread_cancel");
    long thread_ret;
    ret=pthread_join(th_id,(void**)&thread_ret);
    printf("I am main thread, %ld\n",thread_ret);
    return 0;
}